<template>
	<view class="userInfo">
		<view class="userInfo-plate-1">
			<view class="head-pic">
				<image :src="userInfo.head_pic" mode=""></image>
				<u-upload :custom-btn="true" :action="action" @on-success="upSuccess" width="150" header="150" :show-upload-list="false" :deletable="true" name="file[]">
					<view slot="addBtn" class="zhezhao" hover-class="slot-btn__hover" hover-stay-time="150">
						<image src="../../../../static/ic_camera_w.png" mode="widthFix"></image>
					</view>
				</u-upload>
			</view>
			<text>修改头像</text>
		</view>
		<view class="userInfo-plate-2">
			<navigator :url="'alterNickName/alterNickName?nickName=' + userInfo.nickname" open-type="navigate">
				<view class="item">
					<view class="item-title">
						昵称
					</view>
					<view class="item-right">
						<text>{{userInfo.nickname}}</text>
						<u-icon name="arrow-right" color="#666" size="24"></u-icon>
					</view>
				</view>
			</navigator>
			<view class="item">
				<view class="item-title">
					性别
				</view>
				<view class="item-right">
					<u-radio-group v-model="value">
						<u-radio shape="circle" name="1">男</u-radio>
						<u-radio shape="circle" name="2">女</u-radio>
					</u-radio-group>
				</view>
			</view>
			<navigator :url="'alterMobile/alterMobile?mobile='+userInfo.mobile">
				<view class="item">
					<view class="item-title">
						修改/绑定手机号
					</view>
					<view class="item-right">
						<text>{{userInfo.mobile}}</text>
						<u-icon name="arrow-right" color="#666" size="24"></u-icon>
					</view>
				</view>
			</navigator>
			<navigator url="addminAddress/addminAddress" open-type="navigate">
				<view class="item">
					<view class="item-title">
						管理地址
					</view>
					<view class="item-right">
						<text></text>
						<u-icon name="arrow-right" color="#666" size="24"></u-icon>
					</view>
				</view>
			</navigator>
			<navigator url="alterIntro/alterIntro" open-type="navigate">
				<view class="item">
					<view class="item-title">
						简介
					</view>
					<view class="item-right">
						<text>{{userInfo.introduction}}</text>
						<u-icon name="arrow-right" color="#666" size="24"></u-icon>
					</view>
				</view>
			</navigator>
		</view>
		<button class="bg-btn" @click="onSave">保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:'',
				value:'',
				action:this.$Url + '/index.php/app/utils/upload_pic',
				imgUrl:''
			}
		},
		created() {
			this.getUserInfo()
		},
		methods: {
			//请求个人资料
			getUserInfo(){
				uni.request({
				    url:this.$Url +'/index.php/App/Users/userInfo',
				    method:'POST',
				    data:{
				       
				    },
				    header:{
				        "token":uni.getStorageSync('token')
				    },
				    success: (res) => {
				       this.userInfo = res.data.data
					   this.value = res.data.data.sex
					   this.imgUrl = res.data.data.head_pic
				    }
				})
			},
			//上传成功
			upSuccess(res){
				this.imgUrl = res.data.url[0]
				this.onSave()
			},
			//保存资料
			onSave(){
				uni.request({
				    url:this.$Url +'/index.php/App/Users/editInfo',
				    method:'POST',
				    data:{
				       nickname:this.userInfo.nickname,
					   head_pic:this.imgUrl,
					   sex:this.value,
					   mobile:this.userInfo.mobile,
					   introduction:this.userInfo.introduction
				    },
				    header:{
				        "token":uni.getStorageSync('token')
				    },
				    success: (res) => {
						if(res.data.status == 200){
							uni.showToast({
								title:'修改成功',
								icon:'success'
							})
							this.userInfo = res.data.data
							setTimeout(()=>{
								uni.switchTab({
									url:'../../mine'
								})
							},1500)
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
				    }
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.userInfo{
	width: 100vw;
	background-color: #f7f7f7;
	min-height: 100vh;
	.slot-btn__hover {
		background-color: rgb(235, 236, 238);
	}
	.userInfo-plate-1{
		width: 100vw;
		height: 280upx;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		.head-pic{
			width: 150upx;
			height: 150upx;
			border-radius: 50%;
			position: relative;
			>image{
				width: 150upx;
				height: 150upx;
				border-radius: 50%;
			}
			.zhezhao{
				width: 150upx;
				height: 150upx;
				border-radius: 50%;
				background-color: rgba(0,0,0,0.3);
				position: absolute;
				top: 0;
				left: 0;
				z-index: 100;
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					width: 68upx;
				}
			}
		}
		text{
			font-size: 26upx;
			color: #333;
			margin-top: 35upx;
		}
	}
	.userInfo-plate-2{
		width: 100vw;
		.item{
			height: 100upx;
			padding: 0 40upx;
			background-color: #fff;
			margin-top: 10upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.item-title{
				color: #333;
				font-size: 30upx;
			}
			.item-right{
				display: flex;
				align-items: center;
				justify-content: center;
				text{
					font-size: 26upx;
					color: #999;
					margin-right: 5upx;
				}
			}
		}
	}
	.bg-btn{
		width: 350upx;
		height: 90upx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 60upx;
	}
}
</style>
